<template>
  <div class="login_container">
    <div class="login_box">
      <!--      logo区域-->
      <div class="login_logo"></div>
      <!--登录表单区域-->
      <el-form :model="user" ref="formRef">
        <!--用户名-->
        <el-form-item prop="user_name">
          <el-input
            v-model="user.user_name"
            prefix-icon="el-icon-user"
            placeholder="请输入用户名"
          ></el-input>
          <!--验证码-->
        </el-form-item>
        <el-form-item prop="user_pass">
          <el-input
            v-model="user.user_pass"
            prefix-icon="el-icon-lock"
            placeholder="请输密码"
            :type="passwordType"
          >
          </el-input>
        
        </el-form-item>


     
        <!--        按钮-->
        <el-form-item>
          <el-button type="primary" round @click="login" :loading="isLoading"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: "Login",
 
  data() {
    return {
      text: "向右滑动",
      icon: "iconfont icon-eye-on",
      icon1: "iconfont icon-eye-no",
      user: {
        user_name: "",
        user_pass: "",
        // mobile: "",
        // code: "",
       
      },
      passwordType: "password",
      isLoading: false,
   
      redirect: undefined,
    };
  },

  methods: {
   
    // 验证码登录
  

  
    login() {
      // 获取表单数据
      // const user = this.user

      // 打开loading
      this.isLoading = true;

    

      // 传统的登录方式
      axios.post('http://localhost:3500/login',this.user).then((res) => {
          console.log(res);
          console.log(res.data);
          this.$message.success("登录成功");
          // 保存用户token到本地
          window.localStorage.setItem("user", JSON.stringify(res.data.token));
          // 成功后关闭loading
          this.isLoading = false;
          // 跳转到首页
          this.$router.push("/");
        })
        .catch((res) => {
          this.$message.error("用户名或者验证码错误");
          // console.log(res)
          // 失败后关闭loading
          this.isLoading = false;
        });
    },
 
  },
};
</script>

<style lang="scss" scoped>
.login_container {

  background-size: cover;
  height: 100%;

  .login_logo {
    height: 57px;
    // background: url("./logo_index.png") no-repeat center center;
    margin-bottom: 15px;
  }

  .login_box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #ccc;
    padding: 50px;
    min-width: 400px;
    border-radius: 10px;
    // box-shadow: 1px 0 0 rgba(0, 0, 0, 0.3);
    // .tokenpassword{
    //   padding-left: 1px;
    // }


    .el-button {
      width: 100%;
    }
  }
  .showeyes {
    position: absolute;
    top: 0;
    right: 5px;
  }
}
</style>
